#!/usr/bin/env python
import os
import wsgiref.handlers
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

def render_to_response(self, template_name, template_values):
	user = users.get_current_user();
	if (user):
		template_values['user'] = users.get_current_user()
		template_values['logout_url'] = users.create_logout_url('/')
	else:
		template_values['login_url'] = users.create_login_url('/')

	path = os.path.join(os.path.dirname(__file__), template_name)
	self.response.out.write(template.render(path, template_values))

class MainPage(webapp.RequestHandler):
  def get(self):
	self.response.headers['Content-Type'] = 'text/html'
	render_to_response(self, 'index.html', {
		'greeting' : 'Hello, World!',
	})

def main():
  application = webapp.WSGIApplication(
                                       [('/', MainPage)],
                                       debug=True)

  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()


